package cn.gjculture.shopping.api.config;

import cn.gjculture.shopping.api.service.TokenService;
import cn.gjculture.shopping.api.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.filter.HiddenHttpMethodFilter;


@Configuration
public class FilterConfig {
    @Autowired
    TokenService tokenService;
    @Autowired
    UserService userService;

   @Bean
    public FilterRegistrationBean filterRegistration(){
        FilterRegistrationBean registration=new FilterRegistrationBean();
        registration.setFilter(new HiddenHttpMethodFilter());
        registration.addUrlPatterns("/*");
        return registration;
    }

    //跨域过滤器
    @Bean
    public FilterRegistrationBean filter(){
        FilterRegistrationBean registration=new FilterRegistrationBean();
        registration.setFilter(new WebFilter(tokenService,userService));
        registration.addUrlPatterns("/*");
        return registration;
    }
}
